import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;

public class Protest {
    public static void main(String[] args) throws IOException {
        Properties pro = new Properties();
        pro.setProperty("root", "123");
        Scanner sc = new Scanner(System.in);
        while (true){
            System.out.println("是否添加登录信息：输入n退出添加");
            String str=sc.next();
            String str1;
            if (str.equals("n")){
                break;
            }
            else {
                System.out.println("name:");
                str=sc.next();
                System.out.println("pwd:");
                str1=sc.next();
                pro.setProperty(str,str1);
            }
        }
        File file = new File("demo.properties");
        FileOutputStream out = new FileOutputStream(file);
        pro.store(out, null);
        out.close();
        while (true){
            System.out.println("点n退出登录");
            if(sc.next().equals("n")){
                break;
            }
            System.out.println("开始登录:");
            System.out.println("请输入名称:");
            String str = sc.next();
            if (pro.containsKey(str)){
                System.out.println("请输入密码:");
                String str1 = sc.next();
                if(str1.equals(pro.getProperty(str))){
                    System.out.println("登录成功");
                }
                else{
                    System.out.println("登录失败");
                }
            }
            else{
                System.out.println("无此用户");
            }
        }
    }
}
